package o;

import com.huawei.hms.framework.network.restclient.hwhttp.HttpContants;
import com.huawei.hms.framework.network.restclient.hwhttp.RequestBody;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.InputStreamReader;
import java.net.ConnectException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import o.fus.a;
import o.fuu.e;

public class drz {
    public boolean ˏ(File file, dsd o_dsd) {
        Exception e;
        Throwable th;
        List list;
        String str;
        if (file == null || o_dsd == null) {
            Logger.ˋ("AppLogUpload", "uploadFileStream failed.file or param is null");
            return false;
        }
        Logger.ˎ("AppLogUpload", "start uploadFileStream");
        dmz o_dmz = new dmz();
        Map ॱ = o_dsd.ॱ(file.getName());
        String uuid = UUID.randomUUID().toString();
        String str2 = RequestBody.HEAD_VALUE_CONTENT_TYPE_FORM_DATA;
        str2 = "UTF-8";
        String ˊ = o_dsd.ˊ();
        List list2 = null;
        String str3 = null;
        Closeable closeable = null;
        while (true) {
            String str4;
            try {
                fuv ˊ2 = dnb.ˊ();
                e eVar = new e();
                eVar.ˏ(fuu.ˋ);
                for (Entry entry : ॱ.entrySet()) {
                    str4 = (String) entry.getKey();
                    String[] strArr = new String[]{"Content-Disposition", "form-data; name=\"" + str4 + "\"", "Content-Transfer-Encoding", "8bit"};
                    eVar.ˎ(fui.ˋ(strArr), fuw.create(fup.ॱ(RequestBody.DEFAULT_CONTENT_TYPE), (String) entry.getValue()));
                }
                eVar.ˎ(fui.ˋ("Content-Disposition", "form-data; name=\"file\"; filename=\"" + file.getName() + "\""), fuw.create(fup.ॱ("multipart/form-data; charset=UTF-8"), file));
                a ˋ = new a().ˎ(ˊ).ˋ(eVar.ˎ());
                ˋ.ˋ("Charsert", "UTF-8");
                ˋ.ˋ(HttpContants.KEY_CONTENT_TYPE, "multipart/form-data;boundary=" + uuid);
                if (!dof.ˋ(str3)) {
                    ˋ.ˋ("Host", str3);
                }
                Closeable execute = ˊ2.ˎ(ˋ.ॱ()).execute();
                try {
                    int ˊ3 = execute.ˊ();
                    o_dmz.ˋ(execute.ᐝ().ˎ());
                    o_dmz.ˋ(new InputStreamReader(o_dmz.ˋ(), "UTF-8"));
                    o_dmz.ˎ(new BufferedReader(o_dmz.ˊ()));
                    String ˊ4 = doa.ˊ(o_dmz.ˏ(), 1048576);
                    Logger.ˏ("AppLogUpload", "uploadFileStream response SatusCode=" + ˊ3);
                    boolean ˏ = o_dsd.ˏ(ˊ4);
                    dnw.ˎ(null);
                    ˋ(o_dmz);
                    dnw.ˎ(execute);
                    return ˏ;
                } catch (Exception e2) {
                    e = e2;
                    closeable = execute;
                } catch (Throwable th2) {
                    th = th2;
                    closeable = execute;
                }
            } catch (Exception e3) {
                e = e3;
                try {
                    Object obj;
                    Logger.e("AppLogUpload", "LogReport error Exception:" + e.getClass().getSimpleName());
                    if ((e instanceof UnknownHostException) || (e instanceof ConnectException)) {
                        if (list2 == null) {
                            list2 = dmv.ˊ(ˊ, 3000, e);
                        }
                        if (list2.size() > 0) {
                            str4 = ˎ(ˊ);
                            list = list2;
                            str = (String) list2.remove(0);
                            obj = 1;
                        } else {
                            obj = null;
                            str4 = str3;
                            list = list2;
                            str = ˊ;
                        }
                    } else {
                        obj = null;
                        str4 = str3;
                        list = list2;
                        str = ˊ;
                    }
                    dnw.ˎ(null);
                    ˋ(o_dmz);
                    dnw.ˎ(closeable);
                    if (obj == null) {
                        return false;
                    }
                    ˊ = str;
                    list2 = list;
                    str3 = str4;
                } catch (Throwable th3) {
                    th = th3;
                }
            }
            ˊ = str;
            list2 = list;
            str3 = str4;
        }
        dnw.ˎ(null);
        ˋ(o_dmz);
        dnw.ˎ(closeable);
        throw th;
    }

    private String ˎ(String str) {
        String str2 = null;
        if (!dof.ˋ(str)) {
            try {
                str2 = new URL(str).getHost();
            } catch (MalformedURLException e) {
                Logger.e("AppLogUpload", "getHost MalformedURLException:" + e.toString());
            }
        }
        return str2;
    }

    private void ˋ(dmz o_dmz) {
        dnw.ˎ(o_dmz.ˋ());
        dnw.ˎ(o_dmz.ˊ());
        dnw.ˎ(o_dmz.ॱ());
        dnw.ˎ(o_dmz.ˎ());
        dnw.ˎ(o_dmz.ˏ());
        dnw.ˎ(o_dmz.ˏ());
    }
}
